home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
kermit.columbia.edu
/
kermit.columbia.edu.tar
/
kermit.columbia.edu
/
newsgroups
/
misc.20000824-20010305
/
000292_news@columbia.edu _Thu Feb 15 09:45:34 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2001-03-05
|
3KB
Return-Path: <news@columbia.edu>
Received: from watsun.cc.columbia.edu (watsun.cc.columbia.edu [128.59.39.2])
by monire.cc.columbia.edu (8.9.3/8.9.3) with ESMTP id JAA28660
for <kermit.misc@cpunix.cc.columbia.edu>; Thu, 15 Feb 2001 09:45:34 -0500 (EST)
Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id JAA18809
for <kermit.misc@watsun.cc.columbia.edu>; Thu, 15 Feb 2001 09:45:33 -0500 (EST)
Received: (from news@localhost)
by newsmaster.cc.columbia.edu (8.9.3/8.9.3) id JAA14519
for kermit.misc@watsun.cc.columbia.edu; Thu, 15 Feb 2001 09:46:19 -0500 (EST)
X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
From: fdc@columbia.edu (Frank da Cruz)
Subject: Re: interactive/ automated telnet : Better way to do it?
Date: 15 Feb 2001 14:46:18 GMT
Organization: Columbia University
Message-ID: <96gq3q$e5l$1@newsmaster.cc.columbia.edu>
To: kermit.misc@columbia.edu
In article <3A8BDF81.FCCEB0A1@iam.unibe.ch>,
Ibrahim Khalil <ibrahim@iam.unibe.ch> wrote:
: Here is an example of executing a command in a remote machine. Is there a
: faster (sleeps make it slower) and reliable (i.e. works all the time) way to
: do it? Also, how can I grab telnet's stdin and stdout ?
:
: (sleep 1
: echo userid
: sleep 1
: echo password
: sleep 1
: echo ls -la
: sleep 1) |telnet 130.92.66.22
:
The most straightforward, easy, reliable, fast, and flexible way to do this
sort of thing is with a scriptable telnet client such as C-Kermit:
http://www.columbia.edu/kermit/ckermit.html
Here is your script:
#!/usr/local/bin/kermit +
set host \%1
if fail exit 1 Can't reach \%1
input 20 login:
if fail exit 1 Timeout waiting for login prompt
lineout \%2
input 10 Password:
if fail exit 1 Timeout waiting for password prompt
lineout \%3
lineout ls -la
The INPUT command waits until the desired prompt appears, times out and
fails after the given number of seconds if it does not, or else returns
immediately and successfully when it does, so no time is wasted. LINEOUT
sends the given text with the line terminator appropriate to the
connection. IF SUCCESS and IF FAIL can be used to test whether any
command in the script succeeds or fails. Of course EXIT is not the only
choice for handling failure; you can put any other command here you want,
including "procedure calls", blocked groups of statements, etc.
Put the script into a file (note: the first line must not be indented),
give it execute permission, then just run it. In this example, we expect
to receive the hostname-or-address as the first parameter, the username
as the second, the password as the third (obviously not a great idea, but
that's what you wanted). Of course you can also hardwire them into to
the script, prompt for them at runtime, or whatever else you want. For a
more fully elaborated example, see the autotelnet script in:
http://www.columbia.edu/kermit/ckscripts.html
With C-Kermit, you can script anything you could do by hand, as well as
many things you could not do by hand, such as file transfer, arithmetic,
character-set translation, and so on.
- Frank